package com.example.blog_spring.service;

import com.example.blog_spring.mapper.BlogMapper;
import com.example.blog_spring.model.BlogInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BlogService {
    @Autowired
    private BlogMapper blogMapper;

    public List<BlogInfo> getBlogList() {
        List<BlogInfo> blogInfos = blogMapper.selectAllBlog();
        for(BlogInfo tmp : blogInfos){
            if(tmp.getContent().length() > 50) {
                tmp.setContent(tmp.getContent().substring(0, 50));
            }
        }
        return blogInfos;
    }

    public BlogInfo getBlogDetailById(Integer blogId) {
        return blogMapper.selectBlogById(blogId);
    }

    public Integer addBlog(BlogInfo blogInfo) {
        return blogMapper.insertBlog(blogInfo);
    }

    public Integer deleteBlog(BlogInfo blogInfo) {
        return blogMapper.updateBlog(blogInfo);
    }

    public Integer updateBlog(BlogInfo blogInfo) {
        return blogMapper.updateBlog(blogInfo);
    }
}
